#include "filter/map_filter.h"

#include <iostream>

#include "filter/map_filter_impl.h"
#include "generated/version.h"

namespace autodrive {
namespace perception {

MapFilter::MapFilter() : map_filter_impl_ptr_{nullptr} {}

MapFilter::~MapFilter() {}

void MapFilter::Init(MapFilterParameter const &para) noexcept(false) {
  auto initFun{[&]() {
    if (map_filter_impl_ptr_ == nullptr) {
      map_filter_impl_ptr_ = std::make_shared<MapFilterImpl>();
    }
  }};
  std::call_once(init_flag_, initFun);

  try {
    map_filter_impl_ptr_->Init(para);
  } catch (const std::exception &e) {
    throw;
  }
}

bool MapFilter::IsInit() noexcept {
  if (map_filter_impl_ptr_ != nullptr) {
    return map_filter_impl_ptr_->IsInit();
  } else {
    return false;
  }
}

void MapFilter::operator()(Map &map,
                           Eigen::Affine3d const &pose) noexcept(false) {
  try {
    map_filter_impl_ptr_->operator()(map, pose);
  } catch (const std::exception &e) {
    throw;
  }
}

}  // namespace perception
}  // namespace autodrive